package com.flame.system.tools.controller;

import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.system.tools.controller.vo.ServerVo;
import com.flame.system.tools.entity.Server;
import com.flame.system.tools.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * flame_monitor_server 主机信息表
 *
 * @author 吴欣童
 * @since 2022-11-24 21:48:13
 */
@RestController
public class ServerController {

    @Autowired
    private ServerService serverService;

    @PostMapping("/server/connection/test")
    public Result testServerConnection(@RequestBody Server server) {
        serverService.testServerConnection(server);
        return Result.success();
    }

    @PostMapping("/server/page")
    public PageResult pageServer(@RequestBody ServerVo serverVo) {
        return PageResult.success(serverService.pageServer(serverVo));
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/server/add")
    public Result addServer(@RequestBody @Validated Server server) {
        serverService.addServer(server);
        return Result.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/server/update")
    public Result updateServer(@RequestBody @Validated Server server) {
        serverService.updateServer(server);
        return Result.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/server/delete")
    public Result deleteServer(@RequestBody @Validated Server server) {
        serverService.deleteServer(server);
        return Result.success();
    }
}
